package com.kksoft.readcm.a;

import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Handler;
import android.webkit.URLUtil;
import com.kksoft.readcm.activity.App;
import com.kksoft.readcm.objects.ac;
import com.kksoft.readcm.objects.ai;
import com.kksoft.readcm.objects.f;
import com.kksoft.readcm.objects.l;
import com.kksoft.readcm.objects.n;
import com.kksoft.readcm.objects.u;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

public final class ItemAppObservable extends AppObservable         //old e
{
  private final n k;
  private final Object l;
  private n m;
  private final Object n;
  private n o;
  private final w p;
  private AtomicBoolean q;
  private AtomicBoolean r;
  private AtomicBoolean s;
  private AtomicBoolean t;
  private final ArrayList u;
  private AtomicInteger v;
  private AtomicInteger w;
  private String x;
  private ai y;
  private ai z;

  public ItemAppObservable()
  {
    Object localObject1 = new Object();
    this.l = localObject1;
    Object localObject2 = new Object();
    this.n = localObject2;
    w localw = new w(this);
    this.p = localw;
    AtomicBoolean localAtomicBoolean1 = new AtomicBoolean();
    this.q = localAtomicBoolean1;
    AtomicBoolean localAtomicBoolean2 = new AtomicBoolean();
    this.r = localAtomicBoolean2;
    AtomicBoolean localAtomicBoolean3 = new AtomicBoolean();
    this.s = localAtomicBoolean3;
    AtomicBoolean localAtomicBoolean4 = new AtomicBoolean();
    this.t = localAtomicBoolean4;
    AtomicInteger localAtomicInteger1 = new AtomicInteger();
    this.v = localAtomicInteger1;
    AtomicInteger localAtomicInteger2 = new AtomicInteger();
    this.w = localAtomicInteger2;
    ArrayList localArrayList = new ArrayList();
    this.u = localArrayList;
    n localn = new n(true);
    this.k = localn;
    Handler localHandler1 = App.s();
    ai localai1 = new ai(localHandler1, 300L);
    this.y = localai1;
    Handler localHandler2 = App.s();
    ai localai2 = new ai(localHandler2, 400L);
    this.z = localai2;
  }
  
  static n a(ItemAppObservable e1)
  {
      return e1.k;
  }

  static AtomicBoolean b(ItemAppObservable e1)
  {
      return e1.q;
  }

  static ArrayList c(ItemAppObservable e1)
  {
      return e1.u;
  }

  public final int a(l paraml, boolean paramBoolean1, boolean paramBoolean2, boolean paramBoolean3)
  {
    int i;
    if ((paraml == null) || (paraml.c().length() == 0))
      i = -1;
    while (true)
    {
      //return i;
      n localn = this.k;
      String str2 = paraml.d();
      //l locall = localn.a(str2, 0);
      int j;
//      if (locall != null)
//      {
//        if (paramBoolean2)
//        {
//          long l1 = System.currentTimeMillis() / 1000L;
//          a(locall, l1, paramBoolean1);
//        }
//        j = -1;
//        continue;
//      }
      if (!URLUtil.isValidUrl(paraml.c()))
      {
        j = -1;
        continue;
      }
      String str1 = paraml.o();
      //paraml.b(null);
      synchronized (this.n)
      {
        if ((this.o != null) && (paraml.M()))
        {
          this.o.c(paraml);
          j();
          long l2 = System.currentTimeMillis() / 1000L;
          a(paraml, l2, paramBoolean1);
        }
        if (paraml.n() == 0L)
        {
          long l3 = System.currentTimeMillis() / 1000L;
          paraml.a(l3);
        }
        paraml.T();
        paraml.c(0);
        this.k.b(paraml);
        String[] arrayOfString = new String[12];
        String str3 = String.valueOf(paraml.a());
        arrayOfString[0] = str3;
        String str4 = String.valueOf(paraml.b());
        arrayOfString[1] = str4;
        String str5 = paraml.c();
        arrayOfString[2] = str5;
        String str6 = paraml.d();
        arrayOfString[3] = str6;
        String str7 = paraml.e();
        arrayOfString[4] = str7;
        String str8 = paraml.f();
        arrayOfString[5] = str8;
        String str9 = paraml.k();
        arrayOfString[6] = str9;
        String str10 = String.valueOf(paraml.n());
        arrayOfString[7] = str10;
        String str11 = String.valueOf(paraml.C());
        arrayOfString[8] = str11;
        String str12 = String.valueOf(paraml.D());
        arrayOfString[9] = str12;
        String str13 = String.valueOf(paraml.G());
        arrayOfString[10] = str13;
        String str14 = String.valueOf(paraml.s());
        arrayOfString[11] = str14;
        a("INSERT INTO items (item_id, unique_id, given_url, given_normal_url, resolved_url, resolved_normal_url, title, time_added, offline_web, offline_text, is_not_article, percent) VALUES (?,?,?,?,?,?,?,?,?,?,?,?) ", arrayOfString);
//        if ((paraml != null) && (str1 != null))
//          b(paraml, str1, 1, paramBoolean2);
//        if (paramBoolean2)
//        {
//          s locals = this.d;
//          String str15 = paraml.c();
//          locals.a("new", str15);
//        }
//        if ((paramBoolean3) && ((!App.h().getBoolean("autoOnlyOnWifi", 0)) || (App.m())))
//          this.f.b(paraml);
//        if (!paramBoolean1)
//          e();
//        int i1 = paraml.a();
      }
    }
  }

  public final l a(int paramInt)
  {
    Object localObject = this.p.b();
    if (localObject == null)
      localObject = null;
//    while (true)
//    {
//      return localObject;
//      l locall = this.p.c();
//      localObject = ((n)localObject).a(locall, paramInt);
//      if (localObject == null)
//        continue;
//      this.p.a((l)localObject);
//    }
	return null;
  }

  public final n a()
  {
    return this.k;
  }

  public final void a(int paramInt, ac paramac, l paraml, String paramString)
  {
    this.p.a(paramInt, paramac, paraml, paramString);
  }

  public final void a(com.kksoft.readcm.c.c paramc)
  {
    if ((paramc.N()) || (this.t.get()));
    while (true)
    {
      return;
      //paramc.M();
//      int i = this.v.incrementAndGet();
//      s locals = this.d;
//      int j = this.v.get();
//      String str = this.x;
//      int i1 = this.w.get();
//      com.kksoft.readcm.c.c localc = paramc;
      //locals.a(j, str, i1, 0, localc);
    }
  }

  public final void a(com.kksoft.readcm.objects.k paramk)
  {
    synchronized (this.u)
    {
      boolean bool = this.u.add(paramk);
      return;
    }
  }

  public final void a(l paraml)
  {
    if (paraml == null);
    while (true)
    {
      return;
      //paraml.b(1);
//      String[] arrayOfString = new String[2];
//      arrayOfString[0] = "1";
//      String str = String.valueOf(paraml.a());
//      arrayOfString[1] = str;
//      a("UPDATE items SET is_not_article = ?  WHERE item_id = ?", arrayOfString);
    }
  }

  public final void a(l paraml, int paramInt1, int paramInt2, String paramString1, String paramString2, boolean paramBoolean)
  {
    if (paraml == null)
      return;
    String str1;
//    label14: String str2;
//    if (paramString1 != null)
//    {
//      str1 = paramString1;
//      if (paramString2 == null)
//        break label98;
//      str2 = paramString2;
//      label23: if (str1 == null)
//        str1 = "";
//      switch (paramInt1)
//      {
//      default:
//      case 2:
//      case 1:
//      }
//    }
//    while (true)
//    {
//      paraml.e(str1);
//      paraml.d(str2);
//      this.g.a(1);
//      if (paramBoolean)
//        break;
//      d();
//      break;
//      str1 = paraml.v();
//      break label14;
//      label98: str2 = paraml.w();
//      break label23;
//      paraml.a(paramInt2, 1);
//      String[] arrayOfString1 = new String[4];
//      String str3 = String.valueOf(paramInt2);
//      arrayOfString1[0] = str3;
//      arrayOfString1[1] = str1;
//      arrayOfString1[2] = str2;
//      String str4 = String.valueOf(paraml.a());
//      arrayOfString1[3] = str4;
//      a("UPDATE items SET offline_web = ?, mime = ?, encoding = ? WHERE item_id = ?", arrayOfString1);
//      continue;
//      paraml.b(paramInt2, 1);
//      String[] arrayOfString2 = new String[4];
//      String str5 = String.valueOf(paramInt2);
//      arrayOfString2[0] = str5;
//      arrayOfString2[1] = str1;
//      arrayOfString2[2] = str2;
//      String str6 = String.valueOf(paraml.a());
//      arrayOfString2[3] = str6;
//      a("UPDATE items SET offline_text = ?, mime = ?, encoding = ? WHERE item_id = ?", arrayOfString2);
//    }
  }

  public final void a(l paraml, long paramLong, boolean paramBoolean)
  {
    if (paraml == null);
    while (true)
    {
      return;
//      paraml.a(paramLong);
//      String[] arrayOfString = new String[2];
//      String str1 = String.valueOf(paramLong);
//      arrayOfString[0] = str1;
//      String str2 = String.valueOf(paraml.a());
//      arrayOfString[1] = str2;
//      a("UPDATE items SET time_added = ? WHERE item_id = ?", arrayOfString);
//      if (paramBoolean)
//        continue;
//      d();
    }
  }

  public final void a(l paraml, f paramf, boolean paramBoolean1, boolean paramBoolean2)
  {
    if (paraml == null);
    while (true)
    {
      return;
      //int i = paramf.a();
//      f localf = paraml.a(i);
//      if (localf != null)
//      {
//        int j = localf.d();
//        int i1 = paramf.d();
//        if (j == i1)
//        {
//          int i2 = paraml.s();
//          int i3 = paramf.e();
//          if (i2 == i3)
//            continue;
//        }
//      }
      //paraml.a(paramf);
      //this.r.set(1);
//      String[] arrayOfString = new String[7];
//      String str1 = String.valueOf(paraml.a());
//      arrayOfString[0] = str1;
//      String str2 = String.valueOf(paramf.a());
//      arrayOfString[1] = str2;
//      String str3 = String.valueOf(paramf.b());
//      arrayOfString[2] = str3;
//      String str4 = String.valueOf(paramf.c());
//      arrayOfString[3] = str4;
//      String str5 = String.valueOf(paramf.d());
//      arrayOfString[4] = str5;
//      String str6 = String.valueOf(paramf.e());
//      arrayOfString[5] = str6;
//      String str7 = String.valueOf(paramf.f());
//      arrayOfString[6] = str7;
//      a("REPLACE INTO scroll (item_id, view, section, page, node_index, percent, time_updated) VALUES (?,?,?,?,?,?,?)", arrayOfString);
//      if (paramBoolean2)
//      {
//        s locals = this.d;
//        String str8 = paraml.c();
//        locals.a("scroll", str8);
//      }
//      if (paramBoolean1)
//        continue;
//      d();
    }
  }

  public final void a(l paraml, String paramString)
  {
    if ((paraml == null) || (paramString == null) || (paramString.length() == 0) || (!URLUtil.isValidUrl(paramString)));
    while (true)
    {
      return;
//      paraml.a(paramString);
//      this.k.a(paraml);
//      if (this.m != null)
//        this.m.a(paraml);
//      String[] arrayOfString1 = new String[2];
//      String str1 = paraml.e();
//      arrayOfString1[0] = str1;
//      String str2 = String.valueOf(paraml.a());
//      arrayOfString1[1] = str2;
//      a("UPDATE items SET resolved_url = ? WHERE item_id = ?", arrayOfString1);
//      String[] arrayOfString2 = new String[2];
//      String str3 = paraml.f();
//      arrayOfString2[0] = str3;
//      String str4 = String.valueOf(paraml.a());
//      arrayOfString2[1] = str4;
//      a("UPDATE items SET resolved_normal_url = ? WHERE item_id = ?", arrayOfString2);
//      d();
    }
  }

  public final void a(l paraml, String paramString, boolean paramBoolean1, boolean paramBoolean2)
  {
    if (paraml == null);
    while (true)
    {
      return;
//      if (!paraml.k().equals(paramString))
//      {
//        paraml.a(paramString, 1);
//        String[] arrayOfString = new String[2];
//        String str1 = paraml.k();
//        arrayOfString[0] = str1;
//        String str2 = String.valueOf(paraml.a());
//        arrayOfString[1] = str2;
//        a("UPDATE items SET title = ? WHERE item_id = ?", arrayOfString);
//        if (paramBoolean2)
//        {
//          s locals = this.d;
//          String str3 = paraml.c();
//          locals.a("title", str3);
//        }
//        if (paramBoolean1)
//          continue;
//        d();
//        continue;
//      }
    }
  }

  public final void a(l paraml, Map paramMap)
  {
    if ((paraml == null) || (paramMap == null));
    while (true)
    {
      return;
      //Iterator localIterator = paramMap.entrySet().iterator();
      //while (localIterator.hasNext())
      //{
        //f localf = (f)((Map.Entry)localIterator.next()).getValue();
        //a(paraml, localf, 1, 0);
      //}
    }
  }

  public final void a(l paraml, boolean paramBoolean1, boolean paramBoolean2)
  {
//    if (paraml == null);
//    while (true)
//    {
//      return;
//      //String str1 = String.valueOf(paraml.a());
//      paraml.T();
//      paraml.c(1);
//      this.k.c(paraml);
//      //this.s.set(1);
//      //this.r.set(1);
//      this.k.c();
//      String[] arrayOfString1 = new String[1];
//      arrayOfString1[0] = str1;
//      a("DELETE FROM items WHERE item_id = ?", arrayOfString1);
//      String[] arrayOfString2 = new String[1];
//      arrayOfString2[0] = str1;
//      a("DELETE FROM tags WHERE item_id = ?", arrayOfString2);
//      String[] arrayOfString3 = new String[1];
//      arrayOfString3[0] = str1;
//      a("DELETE FROM scroll WHERE item_id = ?", arrayOfString3);
//      String[] arrayOfString4 = new String[1];
//      arrayOfString4[0] = str1;
//      a("DELETE FROM assets_items WHERE item_id = ?", arrayOfString4);
//      if (paramBoolean2)
//      {
//        s locals = this.d;
//        String str2 = paraml.c();
//        locals.a("read", str2);
//      }
//      if (!paramBoolean1)
//        e();
//      c localc = this.i;
//      int i = paraml.a();
//      localc.b(i);
//      if (!paraml.F())
//        continue;
//      this.f.a(paraml);
//    }
  }

  public final void a(n paramn)
  {
    synchronized (this.n)
    {
      this.o = paramn;
      return;
    }
  }

  public final void a(String paramString, int paramInt, com.kksoft.readcm.c.c paramc)
  {
    Object localObject1 = null;
    Object localObject3;
    Object localObject4;
    if ((this.o != null) && (!this.s.get()) && (this.w.get() == paramInt))
    {
      if (paramString != null)
      {
        String str1 = this.x;
        if (paramString.equals(str1));
      }
    }
//    else
//    {
//      localObject3 = this.n;
//      monitorenter;
//      localObject4 = null;
//    }
//    try
//    {
//      this.o = localObject4;
//      monitorexit;
//      boolean bool = this.s.get();
//      this.v.set(1);
//      this.w.set(paramInt);
//      this.x = paramString;
//      this.s.set(0);
//      paramc.L();
//      s locals = this.d;
//      String str2 = paramString;
//      int i = paramInt;
//      com.kksoft.readcm.c.c localc = paramc;
//      locals.a(1, str2, i, bool, localc);
//      return;
//    }
//    finally
//    {
//      monitorexit;
//    }
//    throw localObject2;
  }

  public final void a(String paramString, String[] paramArrayOfString)
  {
    com.kksoft.readcm.objects.k localk = new com.kksoft.readcm.objects.k(paramString, paramArrayOfString);
    synchronized (this.u)
    {
      boolean bool = this.u.add(localk);
      return;
    }
  }

  public final void a(ArrayList paramArrayList)
  {
    synchronized (this.u)
    {
      boolean bool = this.u.addAll(paramArrayList);
      return;
    }
  }

  public final void a(Map paramMap, l paraml)
  {
    if ((paraml == null) || (paramMap == null))
      return;
    paraml.K();
    String[] arrayOfString1 = new String[1];
    String str1 = String.valueOf(paraml.a());
    arrayOfString1[0] = str1;
    a("DELETE FROM items_images WHERE item_id = ?", arrayOfString1);
    Iterator localIterator = paramMap.entrySet().iterator();
    while (true)
    {
      if (!localIterator.hasNext())
      {
        d();
        break;
      }
      com.kksoft.readcm.objects.q localq = (com.kksoft.readcm.objects.q)((Map.Entry)localIterator.next()).getValue();
      paraml.a(localq);
      String[] arrayOfString2 = new String[5];
      String str2 = String.valueOf(paraml.a());
      arrayOfString2[0] = str2;
      String str3 = String.valueOf(localq.b());
      arrayOfString2[1] = str3;
      String str4 = localq.a();
      arrayOfString2[2] = str4;
      String str5 = localq.d();
      arrayOfString2[3] = str5;
      String str6 = localq.c();
      arrayOfString2[4] = str6;
      a("INSERT INTO items_images (item_id, image_id, src, caption, credit) VALUES (?,?,?,?,?) ", arrayOfString2);
    }
  }

  public final void a(boolean paramBoolean)
  {
    this.t.set(paramBoolean);
  }

  public final void a(boolean paramBoolean, com.kksoft.readcm.c.e parame)
  {
    ap localap = new ap(this, paramBoolean, parame);
    Void[] arrayOfVoid = new Void[0];
    AsyncTask localAsyncTask = localap.execute(arrayOfVoid);
  }

  public final void b()
  {
//    if (!this.q.compareAndSet(0, 1));
//    while (true)
//    {
//      return;
//      t localt = new t(this);
//      Void[] arrayOfVoid = new Void[0];
//      AsyncTask localAsyncTask = localt.execute(arrayOfVoid);
//    }
  }

  public final void b(l paraml, String paramString)
  {
//    String str1 = paraml.o();
//    if (paramString.equals(str1));
//    label152: label158: label160: label164: 
//    while (true)
//    {
//      return;
//      int i = paraml.p();
//      if ((paramString == null) || (paramString.length() == 0))
//      {
//        if (i <= 0)
//          break label160;
//        i = 1;
//      }
//      while (true)
//      {
//        if (i == 0)
//          break label164;
//        b(paraml, paramString, 1, 0);
//        break;
//        if (i == 0)
//        {
//          i = 1;
//          continue;
//        }
//        String[] arrayOfString = paramString.split("\\s*?,\\s*?");
//        if (arrayOfString.length != i);
//        for (i = 1; ; i = 0)
//        {
//          if (i != 0)
//            break label158;
//          int j = arrayOfString.length - 1;
//          while (true)
//          {
//            if (j < 0)
//              break label152;
//            if (arrayOfString[j] != 0)
//            {
//              String str2 = paraml.o();
//              String str3 = arrayOfString[j];
//              if (str2.indexOf(str3) == -1)
//              {
//                i = 1;
//                break;
//              }
//            }
//            j += -1;
//          }
//          break;
//        }
//        continue;
//        i = 0;
//      }
//    }
  }

  public final void b(l paraml, String paramString, boolean paramBoolean1, boolean paramBoolean2)
  {
//    if (paraml == null);
//    String str1;
//    do
//    {
//      return;
//      str1 = paramString.toLowerCase().trim();
//    }
//    while (paraml.o().equals(str1));
//    paraml.b(str1);
//    String[] arrayOfString1 = new String[1];
//    String str2 = String.valueOf(paraml.a());
//    arrayOfString1[0] = str2;
//    a("DELETE FROM tags WHERE item_id = ?", arrayOfString1);
//    Iterator localIterator = paraml.q().iterator();
//    while (true)
//    {
//      if (!localIterator.hasNext())
//      {
//        this.k.c();
//        if (paramBoolean2)
//        {
//          s locals = this.d;
//          String str3 = paraml.c();
//          locals.a("tags", str3);
//        }
//        if (paramBoolean1)
//          break;
//        d();
//        break;
//      }
//      String str4 = (String)localIterator.next();
//      String[] arrayOfString2 = new String[2];
//      String str5 = String.valueOf(paraml.a());
//      arrayOfString2[0] = str5;
//      arrayOfString2[1] = str4;
//      a("REPLACE INTO tags (item_id, tag) VALUES (?,?)", arrayOfString2);
//    }
  }

  public final void b(l paraml, boolean paramBoolean1, boolean paramBoolean2)
  {
//    String[] arrayOfString = new String[1];
//    String str1 = String.valueOf(paraml.a());
//    arrayOfString[0] = str1;
//    a("DELETE FROM assets_items WHERE item_id = ?", arrayOfString);
//    if (paramBoolean1)
//    {
//      e locale1 = this;
//      l locall1 = paraml;
//      String str2 = null;
//      locale1.a(locall1, 2, 0, null, str2, 1);
//    }
//    if (paramBoolean2)
//    {
//      e locale2 = this;
//      l locall2 = paraml;
//      int i = 1;
//      String str3 = null;
//      locale2.a(locall2, i, 0, null, str3, 1);
//    }
//    d();
  }

  public final void b(Map paramMap, l paraml)
  {
    if ((paraml == null) || (paramMap == null))
      return;
    paraml.I();
    String[] arrayOfString1 = new String[1];
    String str1 = String.valueOf(paraml.a());
    arrayOfString1[0] = str1;
    a("DELETE FROM items_videos WHERE item_id = ?", arrayOfString1);
    Iterator localIterator = paramMap.entrySet().iterator();
    while (true)
    {
      if (!localIterator.hasNext())
      {
        d();
        break;
      }
      u localu = (u)((Map.Entry)localIterator.next()).getValue();
      paraml.a(localu);
      String[] arrayOfString2 = new String[5];
      String str2 = String.valueOf(paraml.a());
      arrayOfString2[0] = str2;
      String str3 = String.valueOf(localu.b());
      arrayOfString2[1] = str3;
      String str4 = localu.a();
      arrayOfString2[2] = str4;
      String str5 = String.valueOf(localu.d());
      arrayOfString2[3] = str5;
      String str6 = localu.c();
      arrayOfString2[4] = str6;
      a("INSERT INTO items_videos (item_id, video_id, src, type, vid) VALUES (?,?,?,?,?) ", arrayOfString2);
    }
  }

  public final ArrayList c()
  {
    synchronized (this.u)
    {
      ArrayList localArrayList2 = this.u;
      ArrayList localArrayList3 = new ArrayList(localArrayList2);
      return localArrayList3;
    }
  }

  public final void d()
  {
//    ai localai = this.y;
//    h localh = new h(this);
//    localai.a(localh);
  }

  public final void e()
  {
//    al localal = this.h;
//    com.kksoft.readcm.objects.h localh = new com.kksoft.readcm.objects.h(2);
//    localal.a(localh);
//    ai localai = this.y;
//    h localh1 = new h(this);
//    localai.a(localh1);
  }

  public final void f()
  {
//    this.r.set(1);
  }

  public final n g()
  {
	return k;
//    while (true)
//    {
//      Iterator localIterator;
//      synchronized (this.l)
//      {
//        if ((this.m == null) || (this.r.get()))
//          continue;
//        localObject2 = this.m;
//        return localObject2;
//        this.r.set(0);
//        n localn = new n(0);
//        this.m = localn;
//        localIterator = this.k.a().iterator();
//        if (!localIterator.hasNext())
//          localObject2 = this.m;
//      }
//      Object localObject2 = (l)localIterator.next();
//      if (((l)localObject2).s() <= 0)
//        continue;
//      this.m.b((l)localObject2);
//    }
  }

  public final n h()
  {
    synchronized (this.n)
    {
      n localn = this.o;
      return localn;
    }
  }

  public final void j()
  {
//    this.s.set(1);
  }

  public final boolean k()
  {
    return this.s.get();
  }

  public final int l()
  {
    return this.v.get();
  }

  public final int m()
  {
    return this.w.get();
  }

  public final String n()
  {
    return this.x;
  }

  public final void o()
  {
    ai localai = this.z;
    a locala = new a(this);
    localai.a(locala);
  }

  public final boolean p()
  {
    return this.p.a();
  }

  public final l q()
  {
    return this.p.c();
  }

  public final void r()
  {
    this.p.a(0, null, null, null);
  }
}
